package com.weixing.mall.provider.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weixing.mall.base.orm.MPage;
import com.weixing.mall.provider.api.model.dto.SaleAgentDto;
import com.weixing.mall.provider.api.model.query.AgentInfoQuery;
import com.weixing.mall.provider.api.model.query.AgentMemberQuery;
import com.weixing.mall.provider.api.model.vo.*;
import com.weixing.mall.provider.model.domain.Agent;
import com.weixing.mall.provider.model.domain.AgentBonusGroup;
import com.weixing.mall.provider.model.query.AgentQuery;
import com.weixing.mall.provider.model.query.AgentTreeQuery;
import com.weixing.mall.provider.model.query.UpAgentQuery;
import com.weixing.mall.provider.model.vo.AgentTableVo;
import com.weixing.mall.provider.model.vo.AgentTreeVo;
import com.weixing.mall.provider.model.vo.UpAgentVo;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 * 代理商模块-代理商表 Mapper 接口
 * </p>
 *
 * @author Small
 * @since 2019-11-18
 */
public interface AgentMapper extends BaseMapper<Agent> {
    IPage<AgentVo> selectListOfPage(@Param("pg") Page page, @Param("qs") AgentQuery agentQuery);

    AgentVo selectByMobile(@Param(value = "mobile") String mobile);

    AgentVo selectByAgentSn(@Param(value = "agentSn") String agentSn);

    AgentVo selectByAgentInfo(@Param("qs") AgentInfoQuery agentInfoQuery);

    AgentCustomerVo selectByIdAgentCustomer(@Param(value = "agentId") long agentId);

    List<AgentVo> selectByParentId(@Param(value = "agentId") long agentId);

    IPage<AgentTreeVo> structuralTree(@Param("pg") Page page, @Param("qs") AgentTreeQuery agentStructuralTreeQuery);

    IPage<AgentTreeVo> structuralTreeForAgent(@Param("pg") Page page, @Param("qs") AgentTreeQuery query, @Param("agentId") Long agentId, @Param("level") Integer level);

    List<UpAgentVo> selectByUpAgent(@Param("qs") UpAgentQuery upAgentQuery);

    List<Long> selectByCustomerIdAgentLevel(int parseInt, long currentUserId);

    List<Long> selectAgentIdByAgentLevel(int agentLevel);

    IPage<AgentTreeVo> findAgentTreeVoByPId(@Param("pg") Page page, @Param("pid") Long pid);

    IPage<AgentMemberAddressVo> agentMemberAddr(@Param("pg") Page initMpPage, @Param("qs") AgentMemberQuery agentMemberQuery);

    List<UpAgentVo> selectFormAgent(String agentName);


    IPage<AgentTableVo> selectOfPage(@Param("pg") Page page, @Param("qs") AgentMemberQuery agentMemberQuery);

    List<AgentCustomerVo> selectByCustomerId(Long customerId);

    int countKefuGroupCnt(Long customerId);

    List<AgentTreeTableVo> selectTopNode(Long customerId);

    List<AgentTreeTableVo> selectNode(Long agentId);

    IPage<AgentRpcVo> selectChildByAgentId(@Param("pg") Page page, @Param("agentId") long agentId, @Param("agentLevel") Integer agentLevel);

    IPage<AgentRpcVo> selectAgentVoByCustomerId(@Param("pg") Page page, @Param("kefuId") long kefuId);

    List<Agent> selectObligee(Long kefuId);

    List<AgentVo> selectBonusAgent(Long agentId);

    List<Agent> selectObligeeChild(Long agentId);

    List<Agent> listAll();

    List<Agent> listAllByKefuId(Long uid);

    List<Agent> listAllByAgentIdAndAgentLevel(@Param("agentId") long agentId, @Param("agentLevel") Integer agentLevel);

    List<Agent> selectObligor(Long kefuId);

    int countGroupCnt(@Param("agentId") Long agentId, @Param("agentLevel") Integer agentLevel);

    List<AgentBonusGroup> selectObligeeOwn(Long agentId);

    int countTotalByIsOfficial(@Param("isOffcial") Integer isOffcial);

    int countTotalByIsEnable(@Param("isEnable") Integer isEnable);


    int countExpTotal();

    List<String> loadKefuMasterCid();

    IPage<AgentRpcVo> selectChildByAgent(@Param("pg") Page page, @Param("qs")SaleAgentDto dto, @Param("agentLevel")Integer agentLevel);

    List<Agent> selectEnableAll();
}
